﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

namespace StudyRegEx
{
    class Program
    {
        static void Main(string[] args)
        {
            //Version vt, vt1, vt2, vt3;

            args = new string[3];

            args[0] = @"^[A-Z]{2}$";         // una stringa composta da 2 caratteri per 2 volte, totale 4 caratteri
            args[1] = @"GG";
            args[2] = "Nome: Mauro";
            
            Console.WriteLine("Started");
            
            //Console.WriteLine("Total memory is " + GC.GetTotalMemory(true) + " bytes");
            /*vt = new Version();
            vt1 = new Version();
            vt2 = new Version();
            vt3 = new Version();
            GC.Collect();
            Console.WriteLine("Total memory is now " + GC.GetTotalMemory(true) + " bytes");
            Console.WriteLine("Version is " + vt.Build);
            Console.WriteLine();
             */
            Console.WriteLine("Arg1: " + args[0]);
            Console.WriteLine("Arg2: " + args[1]);

            //Match m = Regex.Match(args[2], @"Nome: (.*$)");

            bool ret =  Regex.IsMatch(args[1], args[0], RegexOptions.IgnoreCase);

            Console.WriteLine("Il valore '{0}' matcha {1} ? {2}" , args[1], args[0], ret);

           
            // Caso di estrazione della stringa

            string testo = "Nome: Mauro";
            string pattern = "Nome: ([A-Z]*$)";

            Match m2 = Regex.Match(@testo, @pattern, RegexOptions.IgnoreCase);

            if (m2.Success)
                {
                // Report position as a one-based integer.
                Console.WriteLine(String.Format("'{0}' was found at position {1} in '{2}'.",
                                  m2.Value, m2.Index + 1, testo) + "\n");
                string valore = m2.Groups[1].ToString();
                Console.WriteLine("Il valore è: " + valore);
                }
            else
                Console.WriteLine(String.Format("The pattern '{0}' was not found in '{1}'.",
                                  pattern, testo) + "\n");
            
            /*
            // IsMatch verifica se il primo argomento stringa e' valido per il pattern come secondo argomento
            if (Regex.IsMatch(args[2], args[0]))
                Console.WriteLine("ISMATCH = TRUE");
            else
                Console.WriteLine("ISMATCH = FALSE");
            */

            //Console.WriteLine("Match: " + m.Groups[1]);

            //StreamWriter sw = new StreamWriter(@"c:\temp\trojan.txt");
            //sw.WriteLine("sono un trojan");
            //sw.Close();

            //sw.Dispose();

            //sw = null;



            // continuare da pag 148
            


            Console.ReadKey();

        }

        //private void Nascosto

        public delegate void DelegatoTest (string s);

    }
}
